﻿using System;
public class Node<T>
{
    public Node<T> Next { get; set; }
    public T Data { get; set; }
    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}
public class GenericList<T>
{
    private Node<T> head;
    private Node<T> tail;
    public GenericList()
    {
        tail = head = null;
    }
    public Node<T> Head
    {
        get => head;
    }
    public void Add(T t)
    {
        Node<T> n = new Node<T>(t);
        if (tail == null)
        {
            head = tail = n;
        }
        else
        {
            tail.Next = n;
            tail = n;
        }
    }
    public void ForEach(Action<T> action)
    {
        Node<T> p = head;
        while (p != null)
        {
            action(p.Data);
            p = p.Next;
        }
    }
}
public class Program
{
    static void Main()
    {
        GenericList<int> list = new GenericList<int>();
        for (int i = 0; i < 10; i++)
        {
            list.Add(i);
        }
        int min = int.MaxValue;
        int max = int.MinValue;
        int sum = 0;
        Console.WriteLine("打印数组元素：");
        list.ForEach(Console.WriteLine);
        list.ForEach(m=>min = (min > m) ? m : min);
        list.ForEach(m => max = (max < m) ? m : max);
        list.ForEach(m => sum += m);
        Console.WriteLine("min = {0}", min);
        Console.WriteLine("max = {0}", max);
        Console.WriteLine("sum = {0}", sum);
    }
}